package jdbc;

import jdbc.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author： pang-yun
 * @date： 2021-12-02 17:51
 * 功能目的 ：用于
 */
@Repository
public class DaoImpl implements Dao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void addUser(User user) {
        String sql = "insert into user values(?,?)";
        jdbcTemplate.update(sql, user.getId(), user.getName());

//        String select="select * from user where id=?";
//        User query = jdbcTemplate.queryForObject(select, new BeanPropertyRowMapper<User>(User.class),1);
//        System.out.println(query);
    }

    public User select(int id) {
        String select = "select * from user where id=?";
        User query = jdbcTemplate.queryForObject(select, new BeanPropertyRowMapper<User>(User.class),id);
        return query;
    }
}
